<template>
  <basic-container>
    <avue-crud
      :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @sort-change="sortChange"
    >
      <template slot="menuLeft">
        <div class="curd-foter">
          <div class="redFontBox">
            订单金额：<span class="redFont">{{
              exhibition(statisticsData.orderAmount) || 0
            }}</span>
            元
          </div>
          <div class="redFontBox">
            奖励金额：<span class="redFont">{{
              exhibition(statisticsData.rewardAmount) || 0
            }}</span>
            元
          </div>
          <div class="redFontBox">
            实际入账金额：<span class="redFont">{{
              exhibition(statisticsData.realAmount) || 0
            }}</span>
            元
          </div>
        </div>
      </template>
      <template slot-scope="{}" slot="rpiNoSearch">
        <select-page
          ref="searchRpiSelect"
          label="rpiName"
          value="rpiNo"
          :select.sync="search.rpiNo"
          :url="website.searchLink.merchantUrl"
          placeholder-text="商户"
          filter-key="searchParam"
        ></select-page>
      </template>
      <template slot-scope="{}" slot="serviceNoSearch">
        <select-page
          ref="searchSerSelect"
          label="serviceName"
          value="serviceNo"
          :select.sync="search.serviceNo"
          :url="website.searchLink.serviceUrl"
          placeholder-text="服务商"
          filter-key="searchParam"
        ></select-page>
      </template>
      <template slot-scope="{}" slot="orgNoSearch">
        <select-page
          ref="searchOrgSelect"
          label="serviceName"
          value="serviceNo"
          :select.sync="search.orgNo"
          :url="website.searchLink.orgUrl"
          placeholder-text="机构"
          filter-key="searchParam"
        ></select-page>
      </template>
    </avue-crud>
  </basic-container>
</template>
  
    <script>
import {
  getList,
  getStatistics,
  getExport,
} from "@/api/rb-core/rpiMemberOem/rpi_member_recharge_oem";

import { mapGetters } from "vuex";
import selectPage from "@/components/select-page/select-page";

export default {
  components: {
    selectPage,
  },
  props: {
    rpiMemberNo: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      form: {},
      query: {},
      search: {},
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      statisticsData: {},
      option: {
        height: "calc(50vh - 50px)",
        calcHeight: 30,
        tip: false,
        border: true,
        index: false,
        viewBtn: false,
        editBtn: false,
        addBtn: false,
        delBtn: false,
        selection: false,
        searchMenuSpan: 24,
        columnBtn: false,
        labelWidth: 120, //弹出表单的标题的统一宽度
        searchLabelWidth: 120, //搜索框标题宽度
        menuWidth: 100, //操作栏宽度
        emptyBtnText: "重置",
        // searchIcon:true,
        // searchIndex:3,
        menu: false,
        column: [
          {
            label: "订单类型",
            prop: "rptTradeTypeName",
            type: "input",
            minWidth: 120,
          },
          {
            label: "充值订单号",
            searchLabel: "充值订单号",
            prop: "rechargeOrderCode",
            type: "input",
            overHidden: true,
            minWidth: 180,
          },
          {
            label: "支付订单号",
            searchLabel: "支付订单号",
            prop: "rptOrderCode",
            type: "input",
            overHidden: true,
            minWidth: 180,
          },
          {
            label: "官方订单号",
            searchLabel: "官方订单号",
            prop: "rptOtherPayCode",
            type: "input",
            overHidden: true,
            minWidth: 180,
          },
          {
            label: "通道订单号",
            searchLabel: "通道订单号",
            prop: "rptAisleOrderCode",
            type: "input",
            overHidden: true,
            minWidth: 180,
          },
          {
            label: "充值类型",
            prop: "rechargeTypeName",
            type: "input",
            minWidth: 120,
          },
          {
            label: "商户编号",
            searchLabel: "商户",
            prop: "rpiNo",
            type: "select",
            overHidden: true,
            minWidth: 150,
            searchOrder: 3,
          },
          {
            label: "商户名称",
            prop: "rpiName",
            type: "input",
            minWidth: 150,
          },
          {
            label: "会员编号",
            searchLabel: "会员编号",
            prop: "rpiMemberNo",
            type: "input",
            overHidden: true,
            minWidth: 100,
          },
          {
            label: "会员昵称",
            prop: "memberName",
            type: "input",
            minWidth: 150,
          },
          {
            label: "联系方式",
            prop: "mobile",
            type: "input",
            minWidth: 150,
          },
          {
            label: "订单金额",
            prop: "orderAmount",
            type: "input",
            minWidth: 180,
          },
          {
            label: "赠送金额",
            prop: "rewardAmount",
            type: "input",
            minWidth: 180,
          },
          {
            label: "实际变动金额",
            prop: "realAmount",
            type: "input",
            minWidth: 180,
          },
          // {
          //   label: "累计消费笔数",
          //   prop: "tradeCount",
          //   type: "input",
          //   minWidth: 180,
          // },
          {
            label: "变动前余额",
            prop: "beforeBalance",
            type: "input",
            minWidth: 180,
          },
          {
            label: "变动后余额",
            prop: "afterBalance",
            type: "input",
            minWidth: 180,
          },
          {
            label: "订单状态",
            prop: "rptPayStateName",
            type: "input",
            minWidth: 150,
          },
          {
            label: "卡类型",
            prop: "cardTypeName",
            minWidth: 150,
          },
          {
            label: "门店名称",
            prop: "rpsName",
            type: "input",
            minWidth: 180,
          },
          {
            label: "终端编号",
            prop: "rtNo",
            type: "input",
            minWidth: 180,
          },
          {
            label: "设备序列号",
            prop: "rsSn",
            type: "input",
            minWidth: 180,
          },
          {
            label: "订单日期",
            prop: "rptPayTime",
            type: "input",
            minWidth: 140,
          },
        ],
      },
      data: [],
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        viewBtn: this.vaildData(this.permission.summaryOfCashback_view, false),
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    exhibition() {
      return (val) => {
        if (val == "" || val == "-1") {
          return (val = 0);
        } else {
          return val;
        }
      };
    },
  },
  watch: {
    rpiMemberNo: {
      handler(val) {
        if (val) {
          this.query.rpiMemberNo = val;
          this.onLoad(this.page);
        }
      },
      immediate: true,
    },
  },
  methods: {
    /**
     * @func edit,view 打开之前回调
     * @desc 点击获取点击天数时间
     * */
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then(res => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    /**
     * @func 重置
     * @desc 重置查询条件
     * */
    searchReset() {
      this.query = {};
      this.search = {};
      this.onLoad(this.page);
    },
    /**
     * @func 搜索
     * @desc 根据条件查询
     * @param {params} params --- 条件查询
     * */
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    /**
     * @func 选中单元格
     * @desc 选中单元格数据
     * @param {list} list --- 选中单元格数据-数组
     * */
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    /**
     * @func 分页页码
     * @desc 分页页码改变时会触发
     * */
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      // this.refreshChange();
      this.onLoad(this.page, this.query);
    },
    /**
     * @func 当前页个数
     * @desc pageSize改变时会触发
     * */
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      // this.refreshChange();
      this.onLoad(this.page, this.query);
    },
    /**
     * @func 刷新
     * @desc 点击刷新按钮触发该事件
     * */
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    /**
     * @func 初始化
     * @desc 表格初始化查询数据
     * */
    onLoad(page, params = {}) {
      this.loading = true;
      let paramObj = Object.assign(params, this.query);
      getList(page.currentPage, page.pageSize, Object.assign(paramObj)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });

      getStatistics(page.currentPage, page.pageSize, Object.assign(paramObj)).then((res) => {
        this.statisticsData = res.data.data;
      });
    },
    /**
     * @func 导出
     * @desc 根据条件导出
     * */
    handleExport() {
      let paramObj = this.query;
      this.$confirm("是否导出用户数据?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        getExport(paramObj).then(
          (res) => {
            downloadFileExcel(res);
          },
          (error) => {
            window.console.log(error);
          }
        );
      });
    },
    /**
     * @func 排序
     * @desc 根据表格字段排序
     * */
    sortChange(val) {
      if (val.order == "ascending") {
        //正序
        this.query.ascs = val.prop;
        this.query.descs = "";
      } else {
        //倒序
        this.query.descs = val.prop;
        this.query.ascs = "";
      }
      this.refreshChange();
    },
  },
};
</script>
  
<style lang="scss" scoped>
.curd-foter {
  padding-top: 10px;
  display: flex;
  flex-wrap: wrap;
}

.redFontBox {
  margin-right: 40px;
  .redFont {
    color: red;
  }
}
/deep/ .el-tag--dark.el-tag--success {
  border: none !important;
}
</style>
  